# -*- coding: utf-8 -*-
import time
import easyocr
from submodules.common.lib.log_ import logger
logger =get_logger()


def ocr(file_path):
    t1 = time.time()
    res = []
    # reader = easyocr.Reader(['ch_sim', 'en'], gpu=True)
    reader = easyocr.Reader(['ch_sim'], gpu=True)
    res2 = reader.readtext(file_path)
    for item in res2:
        x1 = item[0][0][0]
        y1 = item[0][0][1]
        x2 = item[0][2][0]
        y2 = item[0][2][1]
        ocr_text = item[1].replace(" ", "")
        ocr_prob = item[2]
        res.append([(x1, y1, x2, y2), ocr_text, ocr_prob])
    t2 = time.time()
    logger.info(f"ocr_time:{t2 - t1}")
    return res


if __name__ == "__main__":
    def test_ocr():
        img_path = "test_data/test.png"
        res = ocr(img_path)
        print(res)


    test_ocr()
